package cn.tedu.ykmall.commodity.webapi.controller;

import cn.tedu.ykmall.commodity.service.ICommodityService;
import cn.tedu.ykmall.common.web.JsonResult;
import cn.tedu.ykmall.pojo.commodity.dto.CategorySpuInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前台商品相关的控制层操作
 */
@RestController
@RequestMapping(value = "/commodity",produces = ("application/json; charset=utf-8"))
public class CommodityController {
    @Autowired
    ICommodityService commodityService;

    /**
     * 响应get请求，调用业务逻辑层的getCommodityInfoById(Long id)方法
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public JsonResult<CategorySpuInfoDTO> getCommodityInfoById(@PathVariable Long id){
        CategorySpuInfoDTO commodity = commodityService.getCommodityInfoById(id);
        return JsonResult.ok(commodity);
    }
}
